// ts 中的类

class Greeter {
  // 静态属性
  static cname: string = "Greeter";
  //   成员熟悉
  greeting: string;

  //   构造函数
  constructor(message: string) {
    this.greeting = message;
  }

  //  静态方法
  static getClassName(): string {
    return "class name is greeter!";
  }

  //   成员方法
  greet() {
    return "hello," + this.greeting;
  }
}

let greeter = new Greeter("world");

// console.log(greeter.greet());

const passCode = "Hello TypeScript";

class Employee {
  // 私有变量
  private _fullName: string = "";

  get fullName(): string {
    return "爷的大名是:" + this._fullName;
  }

  set fullName(newName: string) {
    if (passCode && passCode === "Hello TypeScript") {
      this._fullName = newName;
    } else {
      console.log("Error: Unauthorized update of employee!");
    }
  }
}

let employee = new Employee();

employee.fullName = "xuzy";

// if (employee.fullName) {
//   console.log(employee.fullName);
// }

// 继承
class Animal {
  name: string;

  constructor(theName: string) {
    this.name = theName;
  }

  move(distanceInMeters: number = 0) {
    console.log(`${this.name}moved${distanceInMeters}!`);
  }
}

class Snake extends Animal {
  constructor(name: string) {
    super(name);
  }

  move(distanceInMeters = 5) {
    super.move(distanceInMeters);
  }
}

const sam = new Snake("Sammy the Python");

// sam.move();

//  es私有字段
class Person {
  #name: string;

  constructor(name: string) {
    this.#name = name;
  }

  greet() {
    console.log(`Hello, my name is ${this.#name}!`);
  }
}

let semlinker = new Person("Semlinker");

//!   semlinker.#name;
//     ~~~~~
// Property '#name' is not accessible outside class 'Person'
// because it has a private identifier.

semlinker.greet();
